package com.springboot.cloud.demos.ribbon.rest;

import com.springboot.cloud.common.core.entity.vo.Result;
import com.springboot.cloud.demos.entity.form.WalletForm;
import com.springboot.cloud.demos.entity.po.Wallet;
import com.springboot.cloud.demos.ribbon.service.UnitService;
import com.springboot.cloud.demos.ribbon.service.WalletService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class WalletController {

    @Autowired
    private WalletService walletService;

    @GetMapping("/wallet")
    public Result<Wallet> query(@RequestParam("userId") String userId) {
        return walletService.query(userId);
    }

    @GetMapping("/wallet/{id}")
    public Result<Wallet> get(@PathVariable(value = "id") String id) {
        return walletService.get(id);
    }

    @DeleteMapping("/wallet/{id}")
    public Result delete(@PathVariable(value = "id") String id) {
        return walletService.delete(id);
    }

    @PostMapping("/wallet")
    public Result add(@RequestBody WalletForm walletForm) {
        return walletService.save(walletForm);
    }

    @PutMapping(value = "/wallet")
    public Result update(@RequestBody WalletForm walletForm) {
        return walletService.update(walletForm);
    }
}
